#include "Piece.h"
#include "rect.h"
#include <stdio.h>
#include "V2D.h"
#define CIRCLE_SIZE			.05f
//There aren't many functions the piece class needs on it's own, because they're going to be too big.
//The move function, and the glDraw function.

void Piece::move(Cell cell)
{
	//printf("Moving Cell.");
	x = cell.getX();
	y = cell.getY();
	drawed = true;
	currentPos = cell;
} //It doesn't seem like much does it? Maybe I can have another move function that just has two ints...

void Piece::move(float ex, float why)
{
	x = ex;
	y = why;
//	printf("Piece X2: %f, Piece Y2: %f \n", x, y);
	drawed = true;
}

void Piece::glDraw()
{
	Rect<float> hi;
	if(drawed)
	{
		hi.set((x-.02),(y-.02), .04, .04);
		switch(colorOfOwner)
		{
		case 0:
			glColor3ub(255, 0, 0);
			break;
		case 1:
			glColor3ub(0, 255, 0);
			break;
		case 2:
			glColor3ub(255, 255, 0);
			break;
		case 3:
			glColor3ub(0, 55, 255); //This blue is a bit too dark, so I'm trying to figure out how to lighten it up a little bit.
			break;
		}
		if(selected)
		{
			glColor3ub(255, 255, 255);
		}
		hi.glDraw();
		hi.glDrawOutline();
	}
}

void Piece::showNextPossibleMoves(Cell & c, Map & m)
{
	//Hey neal, I hope you don't mind if I work on this code a bit. -Matt
	V2DF futureRightPosition(c.getX() + (c.getDots() * 0.3), c.getY()); //Right
	V2DF futureLeftPosition(c.getX() - (c.getDots() *0.3), c.getY()); //Left
	V2DF futureUpperRightPosition(c.getX() + (c.getDots() * .15), c.getY() + (c.getDots() * 0.3)); //Upper Right
	V2DF futureUpperLeftPosition(c.getX() - (c.getDots() *.15), c.getY() + (c.getDots() * 0.3)); //Upper Left
	V2DF futureLowerRightPosition(c.getX() + (c.getDots() *.15), c.getY() - (c.getDots() *0.3)); //Lower Left
	V2DF futureLowerLeftPosition(c.getX() - (c.getDots() *.15), c.getY() - (c.getDots() *0.3)); //Lower Right
	
	float futureUpperAndLowerRightPositionX = c.getX() + (c.getDots() * 0.15);
	float futureUpperRightAndLeftPositionY = c.getY() + (c.getDots() * 0.3);
	float futureRightPositionX = c.getX() + (c.getDots() * 0.3);
	float futureLeftPositionX = c.getX() - (c.getDots() * 0.3);
	float futureLowerRightAndLeftPositionY = c.getY() - (c.getDots() * 0.3);
	float futureUpperAndLowerLeftPositionX = c.getX() - (c.getDots() * 0.15);
	//For the case to the right.
	if(!(futureRightPositionX > 0.9) && m.getCell(c.getCol() + (c.getDots() * 2), c.getRow()).drawned())
	{
		glDrawCircle(futureRightPositionX, c.getY(), CIRCLE_SIZE);
		m.getCell(futureRightPositionX, c.getY()).next();
	}
	//For the case to the left.
	if(!(futureLeftPositionX < -0.9) && m.getCell(c.getCol() - (c.getDots() * 2), c.getRow()).drawned())
	{
		glDrawCircle(futureLeftPositionX, c.getY(), CIRCLE_SIZE);
		m.getCell(futureLeftPositionX, c.getY()).next();
	}
	//For the upper right case
	if(!(futureUpperAndLowerRightPositionX < -0.9) && !(futureUpperRightAndLeftPositionY < -0.9) && m.getCell(c.getCol() + c.getDots(), c.getRow() - c.getDots()).drawned())
	{
		glDrawCircle(futureUpperAndLowerRightPositionX, futureUpperRightAndLeftPositionY, CIRCLE_SIZE);
		m.getCell(futureUpperAndLowerRightPositionX, futureUpperRightAndLeftPositionY).next();
	}
	//For the lower right case
	if(!(futureUpperAndLowerRightPositionX < -0.9) && !(futureLowerRightAndLeftPositionY > 0.9) && m.getCell(c.getCol() + c.getDots(), c.getRow() + c.getDots()).drawned())
	{
		glDrawCircle(futureUpperAndLowerRightPositionX, futureLowerRightAndLeftPositionY, CIRCLE_SIZE);
		m.getCell(futureUpperAndLowerRightPositionX, futureLowerRightAndLeftPositionY).next();
	}
	//For the lower left case
	if(!(futureUpperAndLowerLeftPositionX < -0.9) && !(futureLowerRightAndLeftPositionY > 0.9) && m.getCell(c.getCol() - c.getDots(), c.getRow() + c.getDots()).drawned())
	{
		glDrawCircle(futureUpperAndLowerLeftPositionX, futureLowerRightAndLeftPositionY, CIRCLE_SIZE);
		m.getCell(futureUpperAndLowerLeftPositionX, futureLowerRightAndLeftPositionY).next();
	}
	//For the upper left case
	if(!(futureUpperAndLowerLeftPositionX < -0.9) && !(futureUpperRightAndLeftPositionY > 0.9) && m.getCell(c.getCol() - c.getDots(), c.getRow() - c.getDots()).drawned())
	{
		glDrawCircle(futureUpperAndLowerLeftPositionX, futureUpperRightAndLeftPositionY, CIRCLE_SIZE);
		m.getCell(futureUpperAndLowerLeftPositionX, futureUpperRightAndLeftPositionY).next();
	}
}